instancevariables
stocks : seqof StockRecord;
stockWatchers : map StockIdentifier to StockWatcher;
actionLog : seqof ActionEvent := [];
balance : int; inv balance >= 0; -- no stock can have the same name invforall x,y insetinds stocks & x <> y => stocks(x).Name <> stocks(y).Name;
--says that foreach ActionEvent in the log if there exist a next action with the same --Stock name, it should have a different ActionType. this insures that you dont sell or buy the same --two times in a row invlet stockIdentifiers = {si.Name | si insetelems stocks} in forall stockIdentifier inset stockIdentifiers & let allEventsStock = [ e | e inseq actionLog
& e.StockName = stockIdentifier] in
(forall i insetinds allEventsStock &
(i <> len allEventsStock) =>
(allEventsStock(i).Type <> allEventsStock(i+1).Type));
public AddStock: StockRecord * nat1 ==> ()
AddStock(sRecord,priority) == (
stocks := stocks(1,...,priority-1) ^ [sRecord]
^ stocks(priority+1,...,len stocks); if (World`simulate) then stockWatchers(sRecord.Name) := new StockWatcher(sRecord) else stockWatchers(sRecord.Name) := new StockWatcher(sRecord,testValues(sRecord.Name));
) pre sRecord.Name not inset { x.Name | x inseq stocks} post (sRecord.Name insetdom stockWatchers)
and (sRecord = stocks(priority));
public GetActionLog:() ==> seqof ActionEvent
GetActionLog() == return actionLog;
public GetStocksWithActiveActionTrigger: StockState ==> seqof StockRecord
GetStocksWithActiveActionTrigger(ss) == return [e | e inseq stocks
& (stockWatchers(e.Name).GetTriggeredAction() <> nil)
and (e.State = ss)] postlet res = RESULT inforall i insetinds res & res(i).State = ss;
pure FindValidBuy: seqof StockRecord * nat ==> [StockRecord]
FindValidBuy(potBuys,time) == returnlet affordableStocks =
[x | x inseq potBuys & CanAfford(x,balance)] in
( if(len affordableStocks > 0) thenlet x inseq affordableStocks best
(forall y inseq affordableStocks & (stockWatchers(x.Name).GetStockValue(time)) >=
(stockWatchers(y.Name).GetStockValue(time))) in x elsenil
);
pure FindValidSell: seqof StockRecord * nat ==> StockRecord
FindValidSell(potSells,time) == returnlet x inseq potSells best
(forall y inseq potSells &
(stockWatchers(x.Name).GetStockValue(time) - x.Cost) >=
(stockWatchers(y.Name).GetStockValue(time) - y.Cost)) in x prelen potSells > 0 post IsGTAll(stockWatchers(RESULT.Name).GetStockValue(time) - RESULT.Cost,
{stockWatchers(x.Name).GetStockValue(time) - x.Cost | x inseq potSells});
let i insetinds stocks best stocks(i).Name = potAction.Name in
(
stocks(i) := mu(potAction, State |-> <Bought>, Cost |-> value );
sw.updateStockRecord(stocks(i))
)
) pre potAction.State = <PotentialBuy> and
stockWatchers(potAction.Name).GetTriggeredAction() = <Buy> post balance >= 0;
let i insetinds stocks best stocks(i).Name = potAction.Name in
(
stocks(i) := mu(potAction, State |-> <PotentialBuy>, Cost |-> 0);
sw.updateStockRecord(stocks(i))
)
) pre potAction.State = <Bought> and
stockWatchers(potAction.Name).GetTriggeredAction() = <Sell> post balance >= 0;
ObserveAllStocks: nat ==> ()
ObserveAllStocks(time) == forall i insetinds stocks do let stock = stocks(i), csw = stockWatchers(stock.Name) in csw.ObserveStock(time);
public Step: nat ==> ()
Step(time) == (
ObserveAllStocks(time);
let potBuys = GetStocksWithActiveActionTrigger(<PotentialBuy>) ,
potSells = GetStocksWithActiveActionTrigger(<Bought>),
validBuy = FindValidBuy(potBuys,time) in
( if(len potSells > 0) then (PerformSell(FindValidSell(potSells,time), time);) elseskip;
IO`print("\npot sels : ");
IO`print(potSells);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.14Bemerkung:
(vorverarbeitet am 2026-10-11)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.