我有一只熊猫df(见下文).我想添加一个名为"price"的列,我希望从使用函数派生值.我该怎么做呢?
function:
def getquotetoday(symbol):
yahoo = Share(symbol)
return yahoo.get_prev_close()
df:
Symbol Bid Ask
MSFT 10.25 11.15
AAPL 100.01 102.54
(...)
Run Code Online (Sandbox Code Playgroud) 我正在使用pyalgotrade
交易策略,我想在列表中使用多个代码.
它现在的设置方式,它为列表中的每个单独的股票代码运行策略,但我希望它做的是将它们全部作为一个复合策略运行.
我该怎么做呢?
这是代码:
from pyalgotrade.tools import yahoofinance
from pyalgotrade import strategy
from pyalgotrade.barfeed import yahoofeed
from pyalgotrade.technical import stoch
from pyalgotrade import dataseries
from pyalgotrade.technical import ma
from pyalgotrade import technical
from pyalgotrade.technical import highlow
from pyalgotrade import talibext
from pyalgotrade.talibext import indicator
import numpy as np
import talib
testlist = ['aapl', 'msft', 'z']
class MyStrategy( strategy.BacktestingStrategy ):
def __init__( self, feed, instrument ):
strategy.BacktestingStrategy.__init__( self, feed )
self.__position = []
self.__instrument = instrument
self.setUseAdjustedValues( True ) …
Run Code Online (Sandbox Code Playgroud) python quantitative-finance yahoo-finance pyalgotrade ta-lib
我试图找出如何打印以下列表,而不是从第一项开始.要清楚:如果列表是[0,1,2,3,4,5,6,7,8]
,我想打印类似的东西4,5,6,7,8,0,1,2,3
这是代码:
you_can_move_on = False
List = [0,1,2,3,4,5,6,7,8]
next_player = 3
while not you_can_move_on:
next_player = self.get_next_player_index(next_player)
you_can_move_on = self.check_if_I_can_move_on
print(next_player)
def get_next_player_index(self, i):
if i == len(self.players):
return 0
else:
return i+1
def check_if_I_can_move_on(self):
return False
Run Code Online (Sandbox Code Playgroud) 我正试图从雅虎财经中提取数据.
这是我得到的错误:
File "banana.py", line 35, in <module>
data = web.DataReader(ticker, "yahoo", datetime(2011,1,1), datetime(2015,12,31))
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\data.py", line 94, in DataReader
session=session).read()
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\yahoo\daily.py", line 77, in read
df = super(YahooDailyReader, self).read()
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 173, in read
df = self._read_one_data(self.url, params=self._get_params(self.symbols))
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 80, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 91, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "C:\Users\ll\Anaconda2\lib\site-packages\pandas_datareader\base.py", line 117, in _get_response
raise RemoteDataError('Unable to read URL: {0}'.format(url))
pandas_datareader._utils.RemoteDataError: Unable to read URL: http://ichart.finance.yahoo.com/table.csv
Run Code Online (Sandbox Code Playgroud)
当我从.csv文件而不是代码列表中读取时出现错误: …
尝试使用漂亮的汤从网站上刮一张桌子来解析数据.我将如何通过其标题解析它?到目前为止,我甚至无法打印整张桌子.谢谢.
这是代码:
import urllib2
from bs4 import BeautifulSoup
optionstable = "http://www.barchart.com/options/optdailyvol?type=stocks"
page = urllib2.urlopen(optionstable)
soup = BeautifulSoup(page, 'lxml')
table = soup.find("div", {"class":"dataTables_wrapper","id": "options_wrapper"})
table1 = table.find_all('table')
print table1
Run Code Online (Sandbox Code Playgroud)