wäre nicht xTickLabel etwas für dich. Schau mal in der Help nach Axes Properties unter diesem Stichpunkt. Ich denke, damit kommst du ganz schnell weiter.
Jetzt habe ich noch eine Frage: Mit obigem Befehl spreche ich den untersten Plot meiner Grafik an, da dieser zuletzt erstellt wurde stellt er wohl die "aktive Grafik" dar. Wie aktiviere ich die anderen Plots, um auch diese manipulieren zu können?
bei der Help unter dem Stichwort subplot steht, wie du die einzelnen Achsen deiner einzelnen plots anspricht. Ich hatte damit aber bisher auch immer so meine schwierigkeiten und hab viel herumprobiert bis es klappte.
Bei mir wird hier unter Matlab R2009a nichts gelöscht. Deshalb kann ich keinen Verbesserungsratschlag geben. Bitte benutze den Debugger, um genaus zu lokalisieren, wovon die Daten bei Dir gelöscht werden.
das Problem war, dass Graph und x-Achse verschieden viele Datenpunkte besaßen. Das habe ich korrigiert. Der Plot wird jetzt nicht mehr überschrieben, aber dennoch nicht korrekt dargestellt.
Das ist meine main:
Code:
function SpecOut=mrsm_example2()%Markov Regime Switching Models in MATLAB
ts=hist_returns('GLD');
returns = ts(:,2);
indep = ones(size(returns)); % A dummy explanatory variable
k = 2; % How many regimes we expect: bull and bear
S = [11]; % Both the mean and the volatility differ in bulls and bears
function stocks = hist_stock_data(start_date, end_date, varargin) % HIST_STOCK_DATA Obtain historical stock data % hist_stock_data(X,Y,'Ticker1','Ticker2',...) retrieves historical stock % data for the ticker symbols Ticker1, Ticker2, etc... between the dates % specified by X and Y. X and Y are strings in the format ddmmyyyy, % where X is the beginning date and Y is the ending date. The program % returns the stock data in a structure giving the Date, Open, High, Low, % Close, Volume, and Adjusted Close price adjusted for dividends and % splits.
%
% hist_stock_data(X,Y,'tickers.txt') retrieves historical stock data % using the ticker symbols found in the user-defined text file. Ticker % symbols must be separated by line feeds.
%
% EXAMPLES % stocks = hist_stock_data('23012003','15042008','GOOG','C'); % Returns the structure array 'stocks' that holds historical % stock data for Google and CitiBank for dates from January % 23, 2003 to April 15, 2008.
%
% stocks = hist_stock_data('12101997','18092001','tickers.txt'); % Returns the structure arrary 'stocks' which holds historical % stock data for the ticker symbols listed in the text file % 'tickers.txt' for dates from October 12, 1997 to September 18, % 2001. The text file must be a column of ticker symbols % separated by new lines.
%
% stocks = hist_stock_data('12101997','18092001','C','frequency','w') % Returns historical stock data for Citibank using the date range % specified with a frequency of weeks. Possible values for % frequency are d (daily), w (weekly), or m (monthly). If not % specified, the default frequency is daily.
%
% DATA STRUCTURE % INPUT DATA STRUCTURE FORMAT % X (start date) ddmmyyyy String % Y (end date) ddmmyyyy String % Ticker NA String % ticker.txt NA Text file
%
% OUTPUT FORMAT % All data is output in the structure 'stocks'. Each structure % element will contain the ticker name, then vectors consisting of % the organized data sorted by date, followed by the Open, High, Low, % Close, Volume, then Adjusted Close prices.
%
% DATA FEED % The historical stock data is obtained using Yahoo! Finance website. % By using Yahoo! Finance, you agree not to redistribute the % information found therein. Therefore, this program is for personal % use only, and any information that you obtain may not be % redistributed.
%
% NOTE % This program uses the Matlab command urlread in a very basic form. % If the program gives you an error and does not retrieve the stock % information, it is most likely because there is a problem with the % urlread command. You may have to tweak the code to let the program % connect to the internet and retrieve the data.
% split up beginning date into day, month, and year. The month is % subracted is subtracted by 1 since that is the format that Yahoo! uses
bd = start_date(1:2); % beginning day
bm = sprintf('%02d',str2double(start_date(3:4))-1); % beginning month
by = start_date(5:8); % beginning year
% split up ending date into day, month, and year. The month is subracted % by 1 since that is the format that Yahoo! uses
ed = end_date(1:2); % ending day
em = sprintf('%02d',str2double(end_date(3:4))-1); % ending month
ey = end_date(5:8); % ending year
% determine if user specified frequency
temp = find(strcmp(varargin,'frequency') == 1); % search for frequency ifisempty(temp)% if not given
freq = 'd'; % default is daily else% if user supplies frequency
freq = varargin{temp+1}; % assign to user input varargin(temp:temp+1) = []; % remove from varargin end clear temp
% Determine if user supplied ticker symbols or a text file ifisempty(strfind(varargin{1},'.txt'))% If individual tickers
tickers = varargin; % obtain ticker symbols else% If text file supplied
tickers = textread(varargin{1},'%s'); % obtain ticker symbols end
h = waitbar(0, 'Please Wait...'); % create waitbar
idx = 1; % idx for current stock data
% cycle through each ticker symbol and retrieve historical data for i = 1:length(tickers)
% update waitbar to display current ticker waitbar((i-1)/length(tickers),h,sprintf('%s %s %s%0.2f%s', ...
'Retrieving stock data for',tickers{i},'(',(i-1)*100/length(tickers),'%)'))
% download historical data using the Yahoo! Finance website [temp, status] = urlread(strcat('http://ichart.finance.yahoo.com/table.csv?s='...
,tickers{i},'&a=',bm,'&b=',bd,'&c=',by,'&d=',em,'&e=',ed,'&f=',...
ey,'&g=',freq,'&ignore=.csv'));
if status
% organize data by using the comma delimiter [date, op, high, low, cl, volume, adj_close] = ... strread(temp(43:end),'%s%s%s%s%s%s%s','delimiter',',');
stocks(idx).Ticker = tickers{i}; % obtain ticker symbol
stocks(idx).Date = date; % save date data
stocks(idx).Open = str2double(op); % save opening price data
stocks(idx).High = str2double(high); % save high price data
stocks(idx).Low = str2double(low); % save low price data
stocks(idx).Close = str2double(cl); % save closing price data
stocks(idx).Volume = str2double(volume); % save volume data
stocks(idx).AdjClose = str2double(adj_close); % save adjustied close data
% Function for estimation of a general Markov Switching regression
%
% Input: dep - Dependent Variable (vector (univariate model) or matrix (multivariate) ) % indep - Independent variables (explanatory variables), should % be cell array in the case of multivariate model (see examples). % k - Number of states (integer higher or equal to 2) % S - This variable controls for where to include a Markov Switching effect. % See pdf file for details. % advOpt - A structure with advanced options for algorithm. % See pdf file for details.
%
% Output: Spec_Output - A structure with all information regarding the % model estimated from the data (see pdf for details).
%
% Author: Marcelo Perlin (UFRGS/BR) % Contact: marceloperlin@gmail.com
case 'fminunc'
options=optimset('fminunc');
options=optimset(options,'display','off');
[param]=fminunc(@(param)MS_Regress_Lik(dep,indep_nS,indep_S,param,k,S,advOpt,dispOut),param0,options);
case 'fmincon'
options=optimset('fmincon');
options=optimset(options,'display','off');
[param]=fmincon(@(param)MS_Regress_Lik(dep,indep_nS,indep_S,param,k,S,advOpt,dispOut),param0, ...
A,b,Aeq,beq,lB,uB,[],options);
smoothProb=zeros(nr,k);
smoothProb(nr,1:k)=Spec_Output.filtProb(nr,:); % last observation for starting filter
for i=nr-1:-1:1% work backwards in time for smoothed probs for j1=1:k
for j2=1:k
smooth_value(1,j2)=smoothProb(i+1,j2)*filtProb(i,j1)*P(j2,j1)/Prob_t_1(i+1,j2);
end
smoothProb(i,j1)=sum(smooth_value);
end end
die x-Achse überschreibe. xdate gecastet, enthält die Daten 25.10.2011- 22.10.2012 (heute - 1 Jahr). Im Plot allerdings weichen die Werte von xdate ab. Außerdem enthält der Plot 275 anstatt 251 Datenpunkte.
Die Menge an Code sprengt das, was ich für eine Antwort bereit bin durchzulesen. Ich vermute sehr, dass große Bereiche des Codes für Deine eigentliche Frage nicht relevant sind. Es ist aber sehr schwierig, den relevanten Bereich zu finden, wenn ich das Problem noch nicht richtig verstanden habe.
Aussagen wie "der Plot enthält X statt Y Datenpunkts" sind kaum nachzuvollziehen, weil ich nicht wissen kann welches "der Plot" ist und wie Du die Anzahlö der Datenpunkte bestimmt hast.
Könntest Du das Problem also noch deutlich vereinfachen und den relevanten Bereich herausarbeiten?
da habe ich mich wohl undeutlich ausgedrückt. Es war nicht angedacht, dass du den gesamten Code durchliest, relevant ist dies hier:
Code:
function SpecOut=mrsm_example2()%Markov Regime Switching Models in MATLAB
ts=hist_returns('GLD');
returns = ts(:,2);
indep = ones(size(returns)); % A dummy explanatory variable
k = 2; % How many regimes we expect: bull and bear
S = [11]; % Both the mean and the volatility differ in bulls and bears
Allerdings müssen die anhängenden m-files eingebunden werden, damit mrsm_example2 läuft. Ich hatte den Code direkt gepostet, sorry bzgl. des Missverständnisses.
mrsm_example2 startet die anhängenden m-files und manipuliert die Grafik (3 Plots mit identischer x-Achse) die durch MS_Regress_Fit erzeugt wird. Wenn man nun die x-Achsen der Plots untersucht (in der Grafik -> Edit -> Axes Properties) sieht man, dass der Wertebereich (X Limits) von 0 bis 300 reicht. Das wird in MS_Regress_Fit so festgelegt und ist soweit in Ordnung.
Da returns 251 Elemente besitzt, sind die Plots am Ende "leer". Das möchte ich nun nachträglich ändern. Außerdem sollten die Werte der x-Achse nach dem datecast zwischen 28/10/11 und 25/10/12 liegen. Die Plots zeigen aber etwas ganz anderes.
Da returns 251 Elemente besitzt, sind die Plots am Ende "leer". Das möchte ich nun nachträglich ändern. Außerdem sollten die Werte der x-Achse nach dem datecast zwischen 28/10/11 und 25/10/12 liegen. Die Plots zeigen aber etwas ganz anderes.
Ich habe leider immer noch nicht verstanden, wo genau welches Problem auftritt. Welcher Befehl macht nicht das, was Du willst?
Wie möchtest Du es ändern, dass die Plots am Ende "leer" sind? Was genau ist der "datecast"? Was zeigen die Plots denn "anderes"?
Beim Durchstöbern des Codes fiel mir auf, dass man einige Schleifen vereinfachen kann, z.B.:
überschreibe ich die Werte der x-Achse des n-ten Plots, richtig? Da xdate 251 Elemente besitzt sollten die x-Achsen nun ebenfalls 251 Elemente besitzen. Das ist aber nicht der Fall, der Wertebereich (X Limits) reicht weiterhin von 0 bis 300.
das sieht schon besser aus. Allerdings werden jetzt auf der x-Achse die Werte 03/01/08 bis 11/08/08 angezeigt, das ist aber nur ein kleiner Teil von xdate. Ich möchte aber das der gesamte Wertebereich von xdate auf der x-Achse angezeigt wird, also 03/01/08 bis 26/10/12. Hierfür müsste ich auch die Granularität der x-Achse ändern, in etwa so: 03/01/08, 15/02/09, 01/05/10, 15/07/11, 26/10/12.
Du kannst Beiträge in dieses Forum schreiben. Du kannst auf Beiträge in diesem Forum antworten. Du kannst deine Beiträge in diesem Forum nicht bearbeiten. Du kannst deine Beiträge in diesem Forum nicht löschen. Du kannst an Umfragen in diesem Forum nicht mitmachen. Du kannst Dateien in diesem Forum posten Du kannst Dateien in diesem Forum herunterladen
MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.