octave runs ok but plot is not displayed?
Solution 1
I got the answer here. Octave by default uses fltk
for plotting etc, which is failing to work, using gnuplot
works here. Just add below lines to .octaverc
file in your home directory.
graphics_toolkit("gnuplot")
So that every time octave starts it will set the default package for plotting to gnuplot
Solution 2
I do know that's an old question but since I ran into quite the same error yesterday, maybe this can help someone else, too:
According to the Octave wiki pages, there seems to be a problem with plotting and the "oct2mat"-library. For me, the problem was solved after I ran this at the octave command prompt:
pkg rebuild -noauto oct2mat
and restarted octave. When you need to use "oct2mat", type:
pkg load oct2mat
Hope that helps!
heavy rocker dude
Updated on June 04, 2022Comments
-
heavy rocker dude almost 2 years
HI there I am using Octave 2.3.4 with a plot command. I am new at Octave. This plot does not display for some reason. Here is my M file sample:
1; clear all; %%%%%%%%% parameters setting %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% r=0.01; %risk free rate S0=50; %underlying price 1 %create an implied volatiltiy surface using below parameters: basevol=0.25; %implied volatility at time t=0 and in center of strike axis skewT=-0.001; %icrease in vol for one unit increase in maturity v1=0.1; %defines how much a smile is raised at left end from base vol v3=0.2; %defines how much a smile is raised at right end from base vol nK=100; %no. of strike steps nT=10; %no. of time steps Tmax=1; %maximum value in time axis Kmin=1; %minimum value in strike price axis Kmax=150; %maximum value of strike price axis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% dt=Tmax/(nT-1); Tvec=0:dt:1; dk=(Kmax-Kmin)/(nK-1); Kvec=Kmin:dk:Kmax; Tvec=Tvec'; Kvec=Kvec'; nK=size(Kvec,1); nT=size(Tvec,1); dvolT=ones(nK,nT)*(skewT*dt); dvolT=cumsum(dvolT,2); SmileVec=GetSmile(Kvec,v1,0,v3); dvolK=ones(nK,nT); dvolK=repmat(SmileVec,1,nT); ImpliedVolSurface=ones(nK,nT)*basevol+dvolT+dvolK; %use formula mentioned by John Elder in "Hedging for Financial Derivatives" %this formula gives local volatility using implied volatility function ret=GetLocalVolSurface(ImpliedVolSurface, S, r, Kvec, Tvec) [m,n]=size(ImpliedVolSurface); LocalVolSurface=zeros(m,n); dk=Kvec(2)-Kvec(1); dt=Tvec(2)-Tvec(1); x=ImpliedVolSurface; for i=3:m-2, %loop over strikes for j=1:n-1, %loop over time steps dv_dk=(x(i+1,j)-x(i-1,j))/(2*dk); dv2_dk2=(x(i-1,j)-2*x(i,j)+x(i+1,j))/(dk*dk); dv_dt=(x(i,j+1)-x(i,j))/dt; K=Kvec(i); T=Tvec(j+1); rT=T^0.5; sig=x(i,j); h1=(log(S/K)+r*T+0.5*sig*sig*T)/(sig*rT); numer=sig*sig + 2*T*sig*dv_dt + 2*r*K*T*sig*dv_dk; denom=(1+K*h1*rT*dv_dk)^2 + K*K*T*sig*sig*(dv2_dk2-h1*dv_dk*dv_dk*rT); LocalVolSurface(i,j)=(numer/denom)^0.5; end end ret=LocalVolSurface; endfunction LocalVol_Surface=GetLocalVolSurface(ImpliedVolSurface,S0,r,Kvec,Tvec); AsyImplVols=zeros(nK,1); T=Tvec(nT-1); F=S0*exp(r*T); for i=3:nK-2, % use formula sigBS(F,K)=sigLoc( (F+K)/2 ) K=Kvec(i); lookupK=(F+K)/2; kdiff=abs(Kvec-lookupK); %try to find nearest point in grid kidx=min(find(kdiff==min(kdiff))); if ( (kidx > 3) && (kidx < nK-2) ), AsyImplVols(i)=LocalVol_Surface(kidx); else AsyImplVols(i) = NaN; end end figure(1); plot(Kvec(3:nK-2),[ImpliedVolSurface(3:nK-2,nT-1) LocalVol_Surface(3:nK-2,nT-1) AsyImplVols(3:nK-2)]);
When I run in Octave with no error, the plot is never displayed. It does include gnuplot 1.0.1 which I understand does the graph? Is there something I am not doing or missing? I am also running this on Windows 2003 Server. Thanks
-
Mayukh Sarkar about 6 yearsIn my case, while using Fedora, I was getting a black screen instead of plots. My .octaverc was not present. But this worked like a charm.