Python Matplotlib和Numpy数学
我试图用Matplotlib和Numpy获得一些牵引力,但这并不容易 我正在做一个小项目,开始处理Matplotlib和Numpy,但我被卡住了 代码如下:Python Matplotlib和Numpy数学,python,numpy,matplotlib,stockquotes,Python,Numpy,Matplotlib,Stockquotes,我试图用Matplotlib和Numpy获得一些牵引力,但这并不容易 我正在做一个小项目,开始处理Matplotlib和Numpy,但我被卡住了 代码如下: # Modules import datetime import numpy as np import matplotlib.finance as finance import matplotlib.mlab as mlab import matplotlib.pyplot as plot # Define quote startdate
# Modules
import datetime
import numpy as np
import matplotlib.finance as finance
import matplotlib.mlab as mlab
import matplotlib.pyplot as plot
# Define quote
startdate = datetime.date(2010,10,1)
today = enddate = datetime.date.today()
ticker = 'uso'
# Catch CSV
fh = finance.fetch_historical_yahoo(ticker, startdate, enddate)
# From CSV to REACARRAY
r = mlab.csv2rec(fh); fh.close()
# Order by Desc
r.sort()
### Methods Begin
def moving_average(x, n, type='simple'):
"""
compute an n period moving average.
type is 'simple' | 'exponential'
"""
x = np.asarray(x)
if type=='simple':
weights = np.ones(n)
else:
weights = np.exp(np.linspace(-1., 0., n))
weights /= weights.sum()
a = np.convolve(x, weights, mode='full')[:len(x)]
a[:n] = a[n]
return a
### Methods End
prices = r.adj_close
dates = r.date
ma20 = moving_average(prices, 20, type='simple')
ma50 = moving_average(prices, 50, type='simple')
# Get when ma20 crosses ma50
equal = np.round(ma20,1)==np.round(ma50,1)
dates_cross = (dates[equal])
prices_cross = (prices[equal])
# Get when ma20 > ma50
ma20_greater_than_ma50 = np.round(ma20,1) > np.round(ma50,1)
dates_ma20_greater_than_ma50 = (dates[ma20_greater_than_ma50])
prices_ma20_greater_than_ma50 = (prices[ma20_greater_than_ma50])
print dates_ma20_greater_than_ma50
print prices_ma20_greater_than_ma50
现在我需要这样做:
store the price of the "price_cross"
see if one day after the "ma20_greater_than_ma50" statment is true, if true store the price as "price of the one day after"
now do "next price_cross" - "price of the one day after" (price2 - price1) for all occurences
我该怎么做这个数学题,更重要的是。如何使用Matplotlib和Numpy获得牵引力。我应该买什么书
给我一些线索
致以最诚挚的问候,我想说,你不一定需要出去买任何书。更好(更便宜)的解决方案是查看以下在线教程:
并尝试将文档中的内容拼凑起来,搜索相关关键字。从您所展示的代码(假设是您编写的)中,您对numpy有了一些了解。对于遇到的问题,您需要更具体一点,以获得更具体/详细的帮助。我想说的是,您不一定需要外出购买任何书籍。更好(更便宜)的解决方案是查看以下在线教程:
并尝试将文档中的内容拼凑起来,搜索相关关键字。从您所展示的代码(假设是您编写的)中,您对numpy有了一些了解。您需要对遇到的问题更具体一点,才能获得更具体/详细的帮助。这里是一个列表,您可能会在浏览这些问题后找到对您最重要的部分:
您可能想订阅numpy和/或matplotlib的邮件列表。这里是一个列表,您可能会在浏览后找到对您最重要的部分:
您可能想订阅numpy和/或matplotlib的邮件列表。我同意Josh的观点,但想添加matplotlib库:
我的大部分情节都是从直接复制接近我想要的东西开始,然后修改它以满足我的需要。matplotlib库有很多这样的例子。我同意Josh的观点,但想添加matplotlib库:
我的大部分情节都是从直接复制接近我想要的东西开始,然后修改它以满足我的需要。matplotlib库中有许多这样的例子。matplotlib和numpy有大量有用的函数,在实现之前,您应该先用谷歌搜索
例如,请参见matplotlib movavg函数。matplotlib和numpy有大量有用的函数,在实现之前,您应该始终先搜索 例如,请参见matplotlib movavg函数