mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-15 11:22:18 +08:00
25 lines
818 B
Python
25 lines
818 B
Python
import matplotlib.pyplot as plt
|
|
|
|
|
|
def analyze(context, perf):
|
|
fig = plt.figure()
|
|
ax1 = fig.add_subplot(211)
|
|
perf.portfolio_value.plot(ax=ax1)
|
|
ax1.set_ylabel('portfolio value in $')
|
|
|
|
ax2 = fig.add_subplot(212)
|
|
perf['AAPL'].plot(ax=ax2)
|
|
perf[['short_mavg', 'long_mavg']].plot(ax=ax2)
|
|
|
|
perf_trans = perf.ix[[t != [] for t in perf.transactions]]
|
|
buys = perf_trans.ix[[t[0]['amount'] > 0 for t in perf_trans.transactions]]
|
|
sells = perf_trans.ix[
|
|
[t[0]['amount'] < 0 for t in perf_trans.transactions]]
|
|
ax2.plot(buys.index, perf.short_mavg.ix[buys.index],
|
|
'^', markersize=10, color='m')
|
|
ax2.plot(sells.index, perf.short_mavg.ix[sells.index],
|
|
'v', markersize=10, color='k')
|
|
ax2.set_ylabel('price in $')
|
|
plt.legend(loc=0)
|
|
plt.show()
|