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

📄 trendchaser.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
//  TrendChaser.m//  This file defines the methods for noise traders.//#import "TrendChaser.h"// Implementation of a "trend chasing" noise trader ..@implementation TrendChaser-step {   ShareRequest * aRequest;   double riskyPriceChg;   double riskyRet;   double d1, p0, p1;   if ((diagLevel & METHOD_ENTRY) ||       (diagLevel & METHOD_SCHED))     printf("*** step (TrendChaser) entry\n");   [super step];   liqNeeds  = [self getLiqNeeds];   wealth = [self getWealth];   [self printWealth];   // Calculate demand based on optimal portfolio decision   p0 = [mktStats getRiskyLagPrice:1];   p1 = [mktStats getRiskyLagPrice:0];   // today's price less the price lagged one period   riskyPriceChg = p1 - p0;   // Noise traders will base  their asset allocation on last   //  period's return.  The implication is that they expect   //  prices to continue their current trend.  That is one   //  reason why the buy/sell at market prices.   // since riskyCF is only positive when Earnings are released, we should look   //   at last period's CF.  If it was postive, the riskyRet for that period   //   should be adjusted accordingly   // Note: it is lagged 1 period, because the "zero" lag is the risky CF for THIS   //   trading period   d1 = [mktStats getRiskyLagCF: 1];   riskyRet = (riskyPriceChg  + d1) / p0;   expRiskyRet = riskyRet;   rvar = [mktStats getRiskyRetVar];   //  Determine optimal asset allocation   optRiskyFraction = (riskyRet - riskLessRate) /                 (riskAversion * rvar);   // for kicks set (last) price to previous * (1+riskyret)   //  Just in case return was negative 1 (is this possible?) ensure pos. value   riskyValue = p0 * (1 + riskyRet);   if (riskyValue <= 0) riskyValue = 0.01;   // Calculate units to buy/sell "assuming" price will not change   optRiskyUnits = (wealth * optRiskyFraction) /  riskyValue;    [self printValue];   [self printPortChoice];   aRequest = [ShareRequest create: [self getZone]];   [aRequest setTrader: (id *) self];   [aRequest setUnitPrice: -1];   // If he wants more of the risky asset   if (optRiskyUnits > riskyUnits ) {     [aRequest setGrossUnits: optRiskyUnits - riskyUnits];     [aRequest setNetUnits: optRiskyUnits - riskyUnits];     [mktMaker addRiskyDemand: aRequest];     } else {     [aRequest setGrossUnits: riskyUnits - optRiskyUnits];     [aRequest setNetUnits: riskyUnits - optRiskyUnits];     [mktMaker addRiskySupply: aRequest];     }        [self printDemand];   return self;}-print {  printf("NOISE TEST\n");  return self;}@end

⌨️ 快捷键说明

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