我有这个数据帧
Poloniex_DOGE_BTC Poloniex_XMR_BTC Daily_rets perc_ret
172 0.006085 -0.000839 0.003309 0
173 0.006229 0.002111 0.005135 0
174 0.000000 -0.001651 0.004203 0
175 0.000000 0.007743 0.005313 0
176 0.000000 -0.001013 -0.003466 0
177 0.000000 -0.000550 0.000772 0
178 0.000000 -0.009864 0.001764 0
Run Code Online (Sandbox Code Playgroud)
我正在尝试在perc_ret中运行total_rets
但是我的代码只是复制daily_rets中的值
df['perc_ret'] = ( df['Daily_rets'] + df['perc_ret'].shift(1) )
Poloniex_DOGE_BTC Poloniex_XMR_BTC Daily_rets perc_ret
172 0.006085 -0.000839 0.003309 NaN
173 0.006229 0.002111 0.005135 0.005135
174 0.000000 -0.001651 0.004203 0.004203
175 0.000000 0.007743 0.005313 0.005313
176 0.000000 -0.001013 -0.003466 -0.003466
177 0.000000 …Run Code Online (Sandbox Code Playgroud) 但是我不想使用来自yahoo!finance的数据,我想用我自己的但无法弄清楚如何解析CSV,它的格式如下:
Timestamp Low Open Close High BTC_vol USD_vol [8] [9]
2013-11-23 00 800 860 847.666666 886.876543 853.833333 6195.334452 5248330 0
2013-11-24 00 745 847.5 815.01 860 831.255 10785.94131 8680720 0
Run Code Online (Sandbox Code Playgroud)
我想做的事情如下:
def main(plot):
instruments = ["AA", "AES", "AIG"]
feed = yahoofinance.build_feed(instruments, 2008, 2009, ".")
Run Code Online (Sandbox Code Playgroud)
然后yahoofinance.build_feed(instruments, 2008, 2009, ".")用我的替换CSV
我试过了:
import csv
with open( 'FinexBTCDaily.csv', 'rb' ) as csvfile:
data = csv.reader( csvfile )
def main( plot ): …Run Code Online (Sandbox Code Playgroud) csv algorithmic-trading quantitative-finance pyalgotrade back-testing
我正在比较两个列表以查找新数据是否已添加到数据库“polo”中。
最初列表采用相同的形式,但是现在 'excel' 需要一个随附的坐标值。这是这个原始的 LC:
[x for x in polo_list if x not in excel]
Run Code Online (Sandbox Code Playgroud)
我很想知道我们可以解决这个问题的不同方法(也许我采用了错误的方法),现在是代码示例:
excel = [ ['a','a4'],['b','z4']]
polo = ['a','b','d']
a = [x for x in polo if x not in excel]
print 'new data! ', a
#should print,'new data!' ['d']
Run Code Online (Sandbox Code Playgroud)
感谢您的时间
编辑:啊太棒了!现在看起来很简单!感谢善良的 stackoverflow 社区,我非常喜欢这个网站
我试图将这些时间戳转换为%Y-%m-%d %H:%M格式.这是一个数据样本:
0 1450753200
1 1450756800
2 1450760400
3 1450764000
4 1450767600
Name: ohlcv_start_date, dtype: int64
Run Code Online (Sandbox Code Playgroud)
有人可以解释这些类型的时间戳以及我需要哪些代码来正确转换它们,因为当我使用时:
pd.to_datetime(df[TS], unit='ms').dt.strftime('%Y-%m-%d %H:%M')
Run Code Online (Sandbox Code Playgroud)
它将时间转换为:
0 1970-01-01 00:00
1 1970-01-01 00:00
2 1970-01-01 00:00
3 1970-01-01 00:00
4 1970-01-01 00:00
Run Code Online (Sandbox Code Playgroud)
哪个不对
编辑:谢谢Chum先生.
我实际上要做的是按时间戳合并不同资产的值.每个资产在略有不同的时间开始和结束,经过分析,数据似乎存在差距:
market_trading_pair next_future_timestep_return ohlcv_start_date \
0 Poloniex_ETH_BTC 3.013303e-03 2015-12-22 03
1 Poloniex_ETH_BTC 3.171481e-03 2015-12-22 05
2 Poloniex_ETH_BTC -1.381575e-03 2015-12-22 07
3 Poloniex_ETH_BTC -4.327704e-03 2015-12-22 08
Run Code Online (Sandbox Code Playgroud)
我能想到解决这个问题的最好方法是创建一个新的数据框,并用时间戳增加一个小时来填充行,从这里我可以简单地合并资产数据.知道如何生成升序timstamps吗?
使用这种方法
arrow.utcnow().format('YYYY_MM_DD_HH_mm_ss')
Run Code Online (Sandbox Code Playgroud)
或者箭头中类似的东西是否可以将毫秒添加到时间中?
当我尝试声明任何类型的变量并为其赋值时,编译器会抛出"未使用的变量错误".下面我使用'float'作为变量类型并尝试将其指定为1.5.
#include <stdio.h>
#include <cs50.h>
int main(void)
{
printf("How long is your shower?\n");
int time = GetInt();
float flow = 1.5;
}
Run Code Online (Sandbox Code Playgroud)
编译器抛出此错误:
~/workspace/pset1/ $ make water
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wshadow water.c -lcs50 -lm -o water
water.c:10:11: error: unused variable 'flow' [-Werror,-Wunused-variable]
float flow = 1.5;
^
1 error generated.
make: *** [water] Error 1
Run Code Online (Sandbox Code Playgroud) 简单的问题,我正在尝试熟练使用LC并为项目编写"二十一点".以下是代码示例:
# define globals for cards
SUITS = ['C', 'S', 'H', 'D']
RANKS = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
VALUES = {'A':1, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':10, 'Q':10, 'K':10}
hand = ['C4','HK'] #4 of spades and the king of hearts should total 14
total = 0
for card in hand:
if card[-1] in VALUES:
total += VALUES[card[-1]]
print total
total = 0
print [total+VALUES[card[-1]] for card in …Run Code Online (Sandbox Code Playgroud) inth当用户输入值时,在第10行声明变量.
但是,当代码编译时,它表示它是未声明的.
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("How tall would you like your pyramid?\n");
bool inc = true;
while (inc)
{
int h = GetInt();
if (h <= 23 && h >= 1)
{
inc = false;
}
else
{
printf("your value needs to be between 1 and 26\n");
}
}
for (int i=0; i<=h; i++)
{
printf("#\n");
}
}
Run Code Online (Sandbox Code Playgroud)