Und wenn ich HELP MEMORY eingebe, kommt das hier, falls das wichtig ist:
MEMORY Memory information.
See 'doc memory' for more information on how to make the
best use of memory when running MATLAB.
MEMORY when called without an output argument displays
information about how much memory is available and how
much is currently being used by MATLAB. All values are double
precision and in units of bytes.
USERVIEW = MEMORY returns information about how much memory is
available and how much is currently being used by MATLAB. USERVIEW
is a structure that contains the following fields:
MaxPossibleArrayBytes -- The largest contiguous free memory block.
It is an upper bound on the largest single array that MATLAB can
currently create. This field is the smaller of these two values:
a) The largest contiguous memory block found in the
MATLAB virtual address space, or
b) The total available system memory.
To find the number of elements, divide MaxPossibleArrayBytes
by the size of each element in bytes. For example, divide by
eight for a double matrix. The actual number of elements that
that can be created is always less than this number.
MemAvailableAllArrays -- The total amount of memory available
for data. This field is the smaller of these two values:
a) The total available MATLAB virtual address space, or
b) The total available system memory.
The amount of memory available is guaranteed to be at least
as large as this field.
MemUsedMATLAB -- The total amount of system memory reserved for the
MATLAB process. This is the sum of the physical memory and
potential swap file usage.
[USERVIEW, SYSTEMVIEW] = MEMORY returns additional, and more detailed
information about the current state of memory usage. SYSTEMVIEW is a
structure containing the following:
VirtualAddressSpace -- A 2-field structure that contains the
amount of available memory and the total amount of virtual
memory for the MATLAB process.
SystemMemory -- A 1-field structure that contains the amount of
available system memory. This number includes the amount of
available physical memory and the amount of available swap file
space on the computer running MATLAB.
PhysicalMemory -- A 2-field structure that contains the amount of
available physical memory and the total amount of physical memory
on the computer running MATLAB. It can be useful as a measure
of how much data can be accessed quickly.
The MEMORY function is currently available on PCWIN and PCWIN64 only.
Results will vary depending on the computer running MATLAB, the load
on the computer, and what MATLAB is doing at the time.
Example 1: Run the MEMORY command on a 32-bit Windows system:
>> memory
Maximum possible array: 677 MB (7.101e+008 bytes) *
Memory available for all arrays: 1602 MB (1.680e+009 bytes) **
Memory used by MATLAB: 327 MB (3.425e+008 bytes)
Physical Memory (RAM): 3327 MB (3.489e+009 bytes)
* Limited by contiguous virtual address space available.
** Limited by virtual address space available.
>>
Example 2: Run the MEMORY command on a 64-bit Windows system:
>> memory
Maximum possible array: 4577 MB (4.800e+009 bytes) *
Memory available for all arrays: 4577 MB (4.800e+009 bytes) *
Memory used by MATLAB: 330 MB (3.458e+008 bytes)
Physical Memory (RAM): 3503 MB (3.674e+009 bytes)
* Limited by System Memory (physical + swap file) available.
>>
Example 3: Run the MEMORY command with two outputs on a 32-bit Windows
system:
hab dann einfach ne neue Datei erstellt und dann einfach mit dem Befehl
"save tabellen.mat " eingegeben, doch als ich in meiner ursprünglichen Datei "load tabellen.mat" eingegeben hat, lief es schneller, aber ist am gleichen punkt stehen geblieben!
% Die 4 Schleifen mit den variablen, "r, h, g, u" sind hier die immer % variiert werden! kannst du im "workspace" bei "mResults" sehen for r = 1:iNumRankingPeriods
iRankingPeriod = vRankingPeriod(r);
for h = 1:iNumHoldingPeriods
iHoldingPeriod = vHoldingPeriod(h);
for g = 1:iNumGapPeriods
iGapPeriod = vGapPeriod(g);
for u = 1:iUsingPortfolios
iNumPortfolio = vUsingPortfolio(u);
% Nicht-Überlappende Holding Periods -Index Tracking % iWindowLength wird deklariert als ranking + Holdung +Gap
mWindow = [1:iNumAssets; mWindow]; %spalten werden nummeriert, damit man nachher die felder ohne einträge rausschmeißen kann
% remove assets with NaN's for a = 1:iNumAssets
ifany(isnan(mWindow(2:iRankingPeriod+iGapPeriod+1,a)))
%ifany(isnan(mWindow(2:end,j)))
vLogic(1,a) = 0;
else
vLogic (1,a) = 1;
end end
%durchschnittliche Tagesrendite
mWindowNoNan = mWindow(:,logical(vLogic)); %alte matrix, alte zeilen, aber nur die spalten, in denen auch eine 1 im logischen vektor steht,werden übernommen
vRanking = mean(mWindowNoNan(2:iRankingPeriod+1,:),1); %die 1 hinten stellt sicher, dass matlab jeweils die spalten mittelt!
dQuantileStepSize = 1/iNumPortfolios; %anzahl portfolios..
vQuantile = 0:dQuantileStepSize:1;
vQuantileVAL = quantile(vRanking,vQuantile);
vQuantileVAL(1,1)= vQuantileVAL(1,1) - 0.00001;
% Prüfung der schlechtesten Rankings, ob der Quantilswert for j = 1:size(vRanking,2) if((vRanking(j) > vQuantileVAL (iUsingPortfolio)) && (vRanking(j) <= vQuantileVAL(iUsingPortfolio+1)));
vColsPortfolio = [vColsPortfolio mWindowNoNan(1,j)];
end end
mHolding = mWindow(1+iRankingPeriod+iGapPeriod+1:end,[vColsPortfolio]);
vResults = NaN(1,9+iNumAssetsPerPortfolio);
vResults(1,1) = iRankingPeriod; % number of ranking periods
vResults(1,2) = iGapPeriod; % number of gap periods
vResults(1,3) = iHoldingPeriod; % number of holding periods
vResults(1,4) = i*iHoldingPeriod-iHoldingPeriod+1; %Ranking FROM Period
vResults(1,5) = i*iHoldingPeriod-iHoldingPeriod+iRankingPeriod; % Ranking TO Period
vResults(1,6) = i*iHoldingPeriod-2*iHoldingPeriod+iWindowLength+1; % Holding FROM Period
vResults(1,7) = i*iHoldingPeriod-iHoldingPeriod+iWindowLength; % Holding TO Period
vResults(1,8) = iUsingPortfolio; % used portfolio
vResults(1,9)= mean(mean(mHolding)); % average performance of portfolio in window per period [rows cols] = size(vColsPortfolio);
vResults (1,10:9+cols)= vColsPortfolio;
mResults = [mResults; vResults];
vColsPortfolio =[];
Hi Harald,
also ich hab jeweils nur 1 Datei mal laufen lassen, also z.b. mKurse1 nur und es lief ohne probleme und ohne eine Fehlermeldung wegn des Speichers.
das Problem ist, dass ich die ganzen Daten in einer Datei zusammenfügen muss und dann sich die TagesRenditen ausrechnen und ich später zu dem schluss komme, welches Portfolio das beste für mich ist!
Meine Frage:
1. Wie würdest du den Code effizienter gestalten? ich weiss nicht genau, würdest du die for-Schleifen anders gestalten?
2. wie lösche ist die temporären Variablen, was du meinst.
3. könntest du vielleicht ein bsp. hinschreiben, oder in den Code einfügen, da ich nicht genau weiss, wie du es meinst
es sieht zumindest auf den ersten Blick so aus, als ob du Kennzahlen wie mittlere Tagesrenditen für jede Datei separat berechnen könntest. Aber ich habe bei dem Code dann doch nicht den vollen Überblick.
Zu 1.:
Diese Teile:
Code:
for a = 1:iNumAssets
ifany(isnan(mWindow(2:iRankingPeriod+iGapPeriod+1,a)))
%ifany(isnan(mWindow(2:end,j)))
vLogic(1,a) = 0;
else
vLogic (1,a) = 1;
end end
könnten durch logische Indizierung optimiert werden. Wenn der Code allerdings für eine Datei in vernünftiger Zeit durchläuft, sind solche Optimierung nicht unbedingt nötig.
Achtung: das kann mit einem Genauigkeitsverlust verbunden sein. Also vieleicht mal für den ersten Datensatz ausprobieren, ob die Ergebnisse trotzdem noch akzeptabel sind.
ausrechnet, zeigt er mir immer noch den Fehler an, dass ich zu wenig Speicher hab.
??? Out of memory. Type HELP MEMORY for your options.
so zum anderen:
ich könnte alles seperat betrachten, doch ich muss leider alle zusammen betrachten, damit er die beste Rendite errechnet und er eigentlich mir bei vResults die Aktien, die für jede Spalte zuständig sind, ausgibt, doch er gibt mir lediglich die ersten 8 spalten zahlen aus, wie beim ersten die Rankingperiode, beim 2ten die Gapperiode und so weiter bis 8! und ab 9 sollten dann die ausgewählten Aktien(bzw Zahlen) stehen die am besten sind und nicht wie bei mir NaN!
Weisst du wie ich die raushaue, damit dort zahlen vorkommen?
p.s. muss sagen, dass ich am Anfang von matlab bin und jede Hilfe und z.b. mit verbesserungsvorschläge anhand code sehr gern annehm
der Code ist zu komplex um etwas damit anfangen zu können, ohne die Aufgabe im Detail zu verstehen. Vielleicht findest du das Problem selber und kannst es beheben, wenn du Zeile für Zeile mit dem Debugger durchgehst.
Was die Speicherprobleme angeht: man könnte zumindest die Returns für jede Datei einzeln berechnen. Denke auch daran, nur temporär benötigte Daten freizugeben. Ich glaube z.B., dass du die Kurse nur brauchst, um die returns zu berechnen, danach nicht mehr.
Grüße,
Harald
Einstellungen und Berechtigungen
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.