1
$\begingroup$

I have a problem with the end of my code. I would like to display the last two curves, the problem is that at the beginning the size of YY is 288 and then after the equality with diff, my size goes to 238. So when I display the curves I have exactly the same thing, which is normal. But I wish I could show the curve for a size of 288 and I do not understand why YY changed size after the tie ...

Here is the code:

options = pd.read_csv("/Users/***/Documents/***",sep =',',header = 0)



n=prices.settle_sp_price.size 
x=np.arange(0,n)

p1 =sp.polyfit(x, prices.settle_sp_price,3)
pp1 =np.polyval(p1, x)



diff = prices.settle_sp_price-pp1


Y=np.zeros(prices.settle_sp_price.size)

for i in range(1,prices.settle_sp_price.size):
 if Y[i] > .1*Y[i]:
  Y[i] = 0


Y=np.fft.fft(diff)
PP=np.fft.ifft(Y)
YY=[0]*(prices.settle_sp_price.size+50)
a=[0]*prices.settle_sp_price.size
b=[0]*prices.settle_sp_price.size

print('aa')
print(len(YY))
#=288

#interpolate the difference for 90days
for n in range(prices.settle_sp_price.size,prices.settle_sp_price.size+30):
    YY[n]=0
    for k in range(1,prices.settle_sp_price.size):
     a[k]=np.real(Y[k])
     b[k]=-np.imag(Y[k])
     omk=2*math.pi*(k-1)/prices.settle_sp_price.size 
     YY[n]=YY[n]+a[k]*math.cos(omk*(n-1))+b[k]*math.sin(omk*(n-1))

    YY[n]=-YY[n]/prices.settle_sp_price.size

print('bb')
print(len(YY))
#=288


YY = [c for c in diff]
print('cc')
print(len(YY))
#=238



plt.figure()


plt.plot(x,prices.settle_sp_price,'b');
plt.plot(x,tot,'r')
plt.hold()

plt.xlabel('time(days)')
plt.ylabel(' price')
plt.title('Stock price. Actual vs. theoretical 505 days')
$\endgroup$

closed as off-topic by Marcus Müller, Stanley Pawlukiewicz, lennon310, Matt L., MBaz Aug 20 '18 at 22:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "General programming questions are off-topic here, but can be asked on Stack Overflow." – Marcus Müller, Stanley Pawlukiewicz, lennon310, Matt L., MBaz
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ This is not a signal processing, but a programming question (how to set the displayed range of numbers using pyplot). It is hence off-topic here, but could be asked on StackOverflow.com $\endgroup$ – Marcus Müller Aug 19 '18 at 15:39
  • $\begingroup$ however, plt.xlim. $\endgroup$ – Marcus Müller Aug 19 '18 at 15:39
  • $\begingroup$ sorry I did not pay attention ... I did not understand your plt.xlim $\endgroup$ – bibio95100 Aug 19 '18 at 15:45
  • $\begingroup$ pyplot.xlim is the function whose documentation you should be reading. $\endgroup$ – Marcus Müller Aug 19 '18 at 16:26