Python 金融计算框架 Prophet怎么用,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。
前言
Prophet 是一个 Python 的微框架,用于金融市场。Prophet 可以让开发人员把精力放在金融策略模型、项目组合管理和分析上。
示例代码:
from datetime import datetimefrom prophet import Prophetfrom prophet.data import YahooCloseDatafrom prophet.analyze import default_analyzersfrom prophet.orders import Ordersclass OrderGenerator(object): def __init__(self): super(OrderGenerator, self).__init__() self._data = dict() def run(self, prices, timestamp, cash, **kwargs): symbol = "AAPL" orders = Orders() if (prices.loc[timestamp, symbol] * 100) < cash: orders.add_order(symbol, 100) return ordersprophet = Prophet()prophet.set_universe(['AAPL', 'XOM'])prophet.register_data_generators(YahooCloseData())prophet.set_order_generator(OrderGenerator())backtest = prophet.run_backtest(start=datetime(2010, 1, 1))prophet.register_portfolio_analyzers(default_analyzers)analysis = prophet.analyze_backtest(backtest)print(analysis)# +--------------------------------------+# | sharpe | 1.09754359611 |# | average_return | 0.00105478425027 |# | cumulative_return | 2.168833 |# | volatility | 0.0152560508189 |# +--------------------------------------+# Generate orders for you to execute today# Using Nov, 10 2014 as the date because there might be no data for today's# date (Market might not be open) and we don't want examples to fail.today = datetime(2014, 11, 10)print(prophet.generate_orders(today))# Orders[Order(symbol='AAPL', shares=100)]
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注编程网行业资讯频道,感谢您对编程网的支持。