【发布时间】:2017-08-26 03:41:42
【问题描述】:
寻找股票指数时间序列下跌 10% 或更多的每个实例。我正在努力对其进行编程,以便它了解订单问题(不希望升值 10%)。
理想情况下,代码将:选择值,检查值是否低于 10%,如果不是,则检查下一个,继续检查下一个直到找到一个,然后记录。然后,移动到那个“低谷”或“谷”作为开始,继续检查它之后的值是否比该值小 10% 或更多。
I have an Excel file with dates in the first column and the index value in the second
This is what it outputs which I don't think can be correct based on a graph
# Import Libraries
import pandas as pd
import numpy as np
import peakutils
from peakutils.plot import plot as pplot
from matplotlib import pyplot
import matplotlib.pyplot as plt
from scipy import signal
import csv
import scipy
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.tools import FigureFactory as FF
# from pandas import DataFrame
# Import Excel as array
index = pd.read_csv(r"\Users\Reed_2\Desktop\Indexonly.csv")
print("as Pandas")
print (index.values)
# convert to 2 NumPy arrays
dates = index['Date'].as_matrix()
values = index['Index'].as_matrix()
print("values as NumPy")
print(values)
print("Date values")
print(dates)
# Find peaks
peaks = peakutils.indexes(values, thres=0.1, min_dist=1)
print ("peaks")
print(peaks)
a = np.asarray(peaks)
np.savetxt(r"C:\Users\Reed_2\Desktop\export.csv", a, delimiter=",")
可以访问 Python、R Studio 和 MatLab。更喜欢 Python,因为我最了解它。
非常感谢您对此提供的任何帮助。
【问题讨论】:
标签: python pandas numpy time-series peakutils