⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mktobserverswarm.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
// Tim Jares - MktObserverSwarm.m//    Modification of Template package//// NOTE:  MktModelSwarm is the class, mktModelSwarm is an//    instantiation of the class. (I think)#import "MktObserverSwarm.h"// implementation of sample graphical interface for models.@implementation MktObserverSwarm+createBegin: (id) aZone {  MktObserverSwarm * obj;  id <ProbeMap>  probeMap;    obj = [super createBegin: aZone];  // MODIFY: initialize other display options here.  obj->displayFrequency = 1;  probeMap = [EmptyProbeMap createBegin: aZone];  [probeMap setProbedClass: [self class]];  probeMap = [probeMap createEnd];/*  // MODIFY: set any display parameters here.  [probeMap addProbe: [probeLibrary getProbeForVariable: "displayFrequency"				    inClass: [self class]]];  [probeLibrary setProbeMap: probeMap For: [self class]];*/  return obj;}// MODIFY: possible creation finalization here-createEnd {  return [super createEnd];}-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];    [probeDisplayManager createProbeDisplayFor: mktModelSwarm];  [probeDisplayManager createProbeDisplayFor: self]; //  [controlPanel waitForControlEvent]; // if ([controlPanel getState] == ControlStateQuit) //   return self; // Using probes, we can wait for the user to change //  parameters, and when done they can select "go  [controlPanel setStateStopped];  [mktModelSwarm buildObjects];  // MODIFY: build display objects here.  // turn off  stdio printing ?????  //pr_text = 0;  // create graph for price of risky asset  priceGraph = [Graph create: globalZone];  [priceGraph setTitle: "Risky Asset Price vs. Time"];  [priceGraph setAxisLabelsX: "time" Y: "price"];  [priceGraph setWidth: 400 Height: 250];  [priceGraph pack];  [priceGraph setScaleModeX: 1 Y: 0];  // create elements to draw on the graph  priceElement = [priceGraph createElement];  [[[priceElement setLabel: "price"] setColor: "red"] setWidth: 3];  priceGrapher = [ActiveGraph createBegin: [self getZone]];  [priceGrapher setElement: priceElement];  [priceGrapher setDataFeed: mktModelSwarm];  [priceGrapher setProbedSelector: M(getRiskyPrice)];  priceGrapher = [priceGrapher createEnd];  dividendElement = [priceGraph createElement];/*  [[[dividendElement setLabel: "dividend"] setColor: "black"] setWidth: 3];*/  [[dividendElement setLabel: "dividend"] setColor:  "black"];  dividendGrapher = [ActiveGraph createBegin: [self getZone]];  [dividendGrapher setElement: dividendElement];  [dividendGrapher setDataFeed: mktModelSwarm];  [dividendGrapher setProbedSelector: M(getRiskyCF)];  dividendGrapher = [dividendGrapher createEnd];  fundamentalElement = [priceGraph createElement];  [[fundamentalElement setLabel: "fundamental"] setColor: "blue"];  fundamentalGrapher = [ActiveGraph createBegin: [self getZone]];  [fundamentalGrapher setElement: fundamentalElement];  [fundamentalGrapher setDataFeed: mktModelSwarm];  [fundamentalGrapher setProbedSelector: M(getFundPrice)];  fundamentalGrapher = [fundamentalGrapher createEnd];  // create graph for volume of risky asset trading  volGraph = [Graph create: globalZone];  [volGraph setTitle: "Risky Asset Trading Volume vs. Time"];  [volGraph setAxisLabelsX: "time" Y: "volume"];  [volGraph setWidth: 400 Height: 250];  [volGraph pack];  [volGraph setScaleModeX: 1 Y: 0];  // create elements to draw on the graph  volElement = [volGraph createElement];  [[[volElement setLabel: "volume"] setColor: "red"] setWidth: 3];  volGrapher = [ActiveGraph createBegin: [self getZone]];  [volGrapher setElement: volElement];  [volGrapher setDataFeed: mktModelSwarm];  [volGrapher setProbedSelector: M(getRiskyVol)];  volGrapher = [volGrapher createEnd];/*  useHisto = [Histo create: globalZone];  [useHisto setWidth: 400 Height: 250];  [useHisto setNumPoints: numPredictorsToShow            Labels: pred            Colors: predictorColors];  [useHisto title: "Usage of predictors"];  [useHisto axisLabelsX: "predictor index" Y: "usage of predictor"];  [useHisto pack];*/  return self;}  -buildActions {  [super buildActions];    // Let our market model swarm build its own schedule  [mktModelSwarm buildActions];  // MODIFY: schedule display objects here.  //  Create an ActionGroup for display  displayActions = [ActionGroup create: [self getZone]];  // Schedule the methods to draw our display(s)  [displayActions createActionTo: priceGrapher	      message: M(step)];  [displayActions createActionTo: dividendGrapher     message: M(step)];  [displayActions createActionTo: fundamentalGrapher  message: M(step)];  [displayActions createActionTo: volGrapher  	      message: M(step)];  [displayActions createActionTo: probeDisplayManager message: M(update)];  [displayActions createActionTo: mktModelSwarm	      message: M(updateHisto)];  [displayActions createActionTo: actionCache        message: M(doTkEvents)];  // 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.  displaySchedule = [Schedule createBegin: [self getZone]];  [displaySchedule setRepeatInterval: displayFrequency];  displaySchedule = [displaySchedule createEnd];  [displaySchedule at: 0 createAction: displayActions];/*  [displaySchedule at: 10 createActionTo: self   message: M(stopRunning)];*/  stopSchedule = [Schedule create: [self getZone]];  [stopSchedule at: 3600 createActionTo: controlPanel                        message: M(setStateStopped)];  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.  [displaySchedule activateIn: self];  [stopSchedule activateIn: self];    return [self getActivity];}@end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -