📄 mktbatchswarm.m
字号:
// Tim Jares - MktBatchSwarm.m// Modification of Template package//// NOTE: MktModelSwarm is the class, mktModelSwarm is an// instantiation of the class. (I think)#import "MktBatchSwarm.h"// implementation of sample graphical interface for models.@implementation MktBatchSwarm+createBegin: (id) aZone { MktBatchSwarm * obj; obj = [super createBegin: aZone]; // MODIFY: initialize other display options here. obj->loggingFrequency = 1; obj->experimentDuration = 9000; // 25 years return obj;}-buildObjects { id modelZone; [super buildObjects]; // Create the model we're actually observing. The model // is a subswarm of the observer. The model is created // in its own zone, so storage is segregated. modelZone = [Zone create: [self getZone]]; mktModelSwarm = [MktModelSwarm create: modelZone]; // batch setup is pretty simple at this point [ObjectLoader load: self fromFileNamed: "batch.setup"]; [mktModelSwarm buildObjects]; // could do some data analysis at this point. if (loggingFrequency) { priceGraph = [EZGraph createBegin: [self getZone]]; [priceGraph setGraphics: 0]; [priceGraph setFileOutput: 1]; priceGraph = [priceGraph createEnd]; [priceGraph createSequence: "prices.out" withFeedFrom: mktModelSwarm andSelector: M(getRiskyPrice)]; [priceGraph createSequence: "vol.out" withFeedFrom: mktModelSwarm andSelector: M(getRiskyVol)];/* [priceGraph createSequence: "fund.out" withFeedFrom: mktModelSwarm andSelector: M(getFundPrice)]; [priceGraph createSequence: "riskyCF.out" withFeedFrom: mktModelSwarm andSelector: M(getRiskyCF)]; [priceGraph createSequence: "riskyCFNoiseLag.out" withFeedFrom: mktModelSwarm andSelector: M(getRiskyCFNoiseLag)];*/ } return self;} -buildActions { [super buildActions]; // Let our market model swarm build its own schedule [mktModelSwarm buildActions]; if (loggingFrequency) { // now, the display schedule. NOTE the repeat interval is set // from our own Swarm data structure. Display is frequently the // slowest part of simulation, so redrawing less frequently may help. displayActions = [ActionGroup create: [self getZone]]; [displayActions createActionTo: priceGraph message: M(step)]; displaySchedule = [Schedule createBegin: [self getZone]]; [displaySchedule setRepeatInterval: loggingFrequency]; displaySchedule = [displaySchedule createEnd]; [displaySchedule at: 0 createAction: displayActions]; } stopSchedule = [Schedule create: [self getZone]]; [stopSchedule at: experimentDuration createActionTo: self message: M(stopRunning)]; return self;} -activateIn: (id) swarmContext {// activate te schedules so they're ready to run [super activateIn: swarmContext]; // Activate the model swarm in ourselves. The model swarm // is a subswarm of the observer swarm [mktModelSwarm activateIn: self]; // Now activate our schedule in ourselves. This arranges for the // execution of the schedule we built. if (loggingFrequency) [displaySchedule activateIn: self]; [stopSchedule activateIn: self]; return [self getActivity];}// the MktBatchSwarm had a go method inherited from GUISwarm,// but we have to define our own here. It's pretty simple. There's also// a friendly message printed out here just in case someone is confused// when they run heatbugs and see no graphics.-go { printf( "You typed 'mkt -batchmode', so we're running without graphics.\n"); printf("MARKET is running for %d timesteps.\n",experimentDuration) ; if(loggingFrequency) printf("It is logging data every %d timesteps to: prices.out, vol.out, fund.out.\n", loggingFrequency); [[self getActivity] run]; return [[self getActivity] getStatus];}// And the termination method. When this fires we just terminate everything// that's running and close our output file(s) by dropping the EZGraph which// "owns" the sequence(s) we are logging.-stopRunning { // collect statistics and print them out [mktModelSwarm dumpStatistics]; [getTopLevelActivity() terminate]; // Terminate the simulation. if(loggingFrequency) printf ("\n OUTTA HERE!!"); return self;}@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -