Ejemplo n.º 1
0
        public void Process(PathBlock block)
        {
            var temp = new double[Vector <double> .Count];

            for (var s = 0; s < block.NumberOfSteps; s++)
            {
                for (var f = 0; f < block.Factors; f++)
                {
                    var dim = f * block.NumberOfSteps + s;
                    for (var p = 0; p < block.NumberOfPaths; p += Vector <double> .Count)
                    {
                        var path = p + block.GlobalPathIndex + 1;
                        var x    = GetValueViaGreyCode(path, dim);
                        temp[0] = ConvertRandToDouble(x, dim);
                        for (var i = 1; i < Vector <double> .Count; i++)
                        {
                            path    = i + p + block.GlobalPathIndex + 1;
                            x      ^= _v[dim + _seed][BitShifting.FindFirstSet(~(uint)path) - 1];
                            temp[i] = ConvertRandToDouble(x, dim);
                        }
                        var pathSpan = block.GetStepsForFactor(p, f);
                        pathSpan[s] = new Vector <double>(temp);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void TestBlockGeneration()
        {
            var block         = new PathBlock(64, 1, 10, 0);
            var retVal        = 0.5;
            var gen           = new Constant(retVal);
            var fetCollection = new FeatureCollection();
            var engine        = new FakeEngine();

            fetCollection.AddFeature <IEngineFeature>(engine);
            fetCollection.AddFeature <ITimeStepsFeature>(engine);
            fetCollection.AddFeature <IPathMappingFeature>(engine);

            gen.Process(block);

            for (var i = 0; i < 64 * 10; i++)
            {
                Assert.Equal(retVal, block[i]);
            }

            gen.UseNormalInverse = true;
            gen.Process(block);
            retVal = Statistics.NormInv(retVal);
            for (var i = 0; i < 64 * 10; i++)
            {
                Assert.Equal(retVal, block[i]);
            }
        }
Ejemplo n.º 3
0
        public void Process(PathBlock block)
        {
            for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
            {
                var p1    = block.GetStepsForFactor(path, _assetIndex1);
                var p2    = block.GetStepsForFactor(path, _assetIndex2);
                var p1Arr = new double[Vector <double> .Count][];
                var p2Arr = new double[Vector <double> .Count][];
                for (var i = 0; i < Vector <double> .Count; i++)
                {
                    p1Arr[i] = new double[p1.Length];
                    p2Arr[i] = new double[p2.Length];
                }
                for (var step = 0; step < p1.Length; step++)
                {
                    for (var i = 0; i < Vector <double> .Count; i++)
                    {
                        p1Arr[i][step] = p1[step][i];
                        p2Arr[i][step] = p2[step][i];
                    }
                }

                var correls = new double[Vector <double> .Count];
                for (var i = 0; i < correls.Length; i++)
                {
                    var returns1 = p1Arr[i].Returns(true);
                    var returns2 = p2Arr[i].Returns(true);
                    correls[i] = returns1.Correlation(returns2).Correlation;
                }

                _results.Add(new Vector <double>(correls));
            }
        }
Ejemplo n.º 4
0
        public void Process(PathBlock block)
        {
            var index = 0;

            for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
            {
                for (var factor = 0; factor < block.Factors; factor++)
                {
                    for (var step = 0; step < block.NumberOfSteps; step++)
                    {
                        var dim = step * block.Factors + factor;

                        for (var i = 0; i < Vector <double> .Count; i++)
                        {
                            var pathid = path + i + block.GlobalPathIndex;
                            var point  = CreatePoint(pathid, dim) / Pow(2.0, 32.0);
                            //point = ShiftNumber(point,dim);
                            if (_useNormalInv)
                            {
                                point = Math.Statistics.NormInv(point);
                            }
                            block.RawData[index] = point;
                            index++;
                        }
                    }
                }
            }
            Debug.Assert(block.RawData.Length == index);
        }
Ejemplo n.º 5
0
        public void Process(PathBlock block)
        {
            var nFactors = block.Factors;

            for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
            {
                var randsForSteps = new Vector <double> [nFactors][];
                for (var r = 0; r < randsForSteps.Length; r++)
                {
                    randsForSteps[r] = block.GetStepsForFactor(path, r).ToArray();
                }

                for (var step = 1; step < block.NumberOfSteps; step++)
                {
                    var randsForThisStep = new Vector <double> [nFactors];

                    for (var r = 0; r < randsForThisStep.Length; r++)
                    {
                        randsForThisStep[r] = randsForSteps[r][step];
                    }

                    var correlatedRands = Correlate(randsForThisStep);

                    for (var r = 0; r < randsForSteps.Length; r++)
                    {
                        var x = block.GetStepsForFactor(path, r);
                        x[step] = correlatedRands[r];
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public void Process(PathBlock block)
 {
     for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
     {
         var previousStep = new Vector <double>(_forwardCurve(0));
         var steps        = block.GetStepsForFactor(path, _factorIndex);
         steps[0] = previousStep;
         for (var step = 1; step < block.NumberOfSteps; step++)
         {
             var W      = steps[step];
             var dt     = new Vector <double>(_timesteps.TimeSteps[step]);
             var drifts = new Vector <double>(_drifts[step]);
             var vols   = new double[Vector <double> .Count];
             for (var s = 0; s < vols.Length; s++)
             {
                 vols[s] = System.Math.Sqrt(
                     System.Math.Max(0,
                                     _lvInterps[step - 1].Interpolate(previousStep[s])));
             }
             var volVec = new Vector <double>(vols);
             var bm     = (drifts - volVec * volVec / _two) * dt + (volVec * _timesteps.TimeStepsSqrt[step] * W);
             previousStep *= bm.Exp();
             steps[step]   = previousStep;
         }
     }
 }
Ejemplo n.º 7
0
 public unsafe void Process(PathBlock block)
 {
     if (!UseNormalInverse)
     {
         for (var i = 0; i < block.TotalBlockSize; i = i + (UseAnthithetic ? 2 : 1))
         {
             block[i] = GenerateDouble();
             if (UseAnthithetic)
             {
                 block[i + 1] = 1.0 - block[i];
             }
         }
     }
     else
     {
         for (var i = 0; i < block.TotalBlockSize; i = i + (UseAnthithetic ? 2 : 1))
         {
             block[i] = Math.Statistics.NormInv(GenerateDouble());
             if (UseAnthithetic)
             {
                 block[i + 1] = -block[i];
             }
         }
     }
 }
Ejemplo n.º 8
0
 public void Process(PathBlock block)
 {
     for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
     {
         var steps       = block.GetStepsForFactor(path, _assetIndex);
         var finalValues = steps[_expiryIndex] - (new Vector <double>(_strike));
         finalValues = Vector.Max(new Vector <double>(0), finalValues);
         _results.Add(finalValues);
     }
 }
Ejemplo n.º 9
0
    public List <BlockController> GetPath(PathBlock start, PathBlock finish)
    {
        var waypoints    = new List <BlockController>();
        var currentBlock = finish;

        while (currentBlock != start)
        {
            waypoints.Insert(0, currentBlock.block);
            currentBlock = currentBlock.parent;
        }
        waypoints.Insert(0, start.block);
        return(waypoints);
    }
Ejemplo n.º 10
0
        public void FindPath()
        {
            if (isMaked)
            {
                var EntryPoint = RandomPick <MyGridPoint> .Pick(new List <MyGridPoint> {
                    new MyGridPoint(random.Next() % (Rows / 2), 0),
                    new MyGridPoint(0, random.Next() % (Cols / 2))
                });

                PathBlock RootBlock = new PathBlock {
                    Data = mazeBlocks.GetBorder(EntryPoint)
                };
            }
        }
Ejemplo n.º 11
0
    void Update()
    {
        RaycastHit hitInfo;
        bool       isGrounded = Physics.Linecast(groundCheckPoint.position, groundCheckPoint.position + Vector3.down, out hitInfo);


        if (isGrounded)
        {
            currentCoyoteTime = coyoteTime;
            playerVelocity.y  = 0f;

            PathBlock pathBlock = hitInfo.collider.GetComponent <PathBlock>();
            if (pathBlock != null && pathBlock.CanTouch)
            {
                OnNewBlockTouched();
                pathBlock.SetTouched();
            }
            characterAnimator.SetBool(InAir, false);
        }
        else if (0 <= currentCoyoteTime)
        {
            currentCoyoteTime -= Time.deltaTime;
        }
        else
        {
            playerVelocity.y += Physics.gravity.y * Time.deltaTime * fallSpeedMultiplier;
            characterAnimator.SetBool(InAir, true);
        }


        float xAxis = variableJoystick.Horizontal;
        float yAxis = variableJoystick.Vertical;


        Vector3 moveVector         = new Vector3(xAxis, 0, yAxis);
        Vector3 relativeMoveVector = Camera.main.transform.TransformVector(moveVector);

        relativeMoveVector.y = 0;


        characterController.Move(relativeMoveVector * Time.deltaTime * moveSpeed);

        // if (transform.rotation != Quaternion.LookRotation (relativeMoveVector))
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(relativeMoveVector), Time.deltaTime * rotationSpeed);
        }


        characterController.Move(playerVelocity * Time.deltaTime);
    }
Ejemplo n.º 12
0
 public void Process(PathBlock block)
 {
     for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
     {
         var steps       = block.GetStepsForFactor(path, _assetIndex);
         var finalValues = new Vector <double>(0.0);
         for (var i = 0; i < _dateIndexes.Length; i++)
         {
             finalValues += steps[_dateIndexes[i]];
         }
         finalValues = (new Vector <double>(_strike)) - (finalValues / new Vector <double>(_dateIndexes.Length));
         finalValues = Vector.Max(new Vector <double>(0), finalValues);
         _results.Add(finalValues);
     }
 }
Ejemplo n.º 13
0
 public void Process(PathBlock block)
 {
     for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
     {
         var previousStep = new Vector <double>(_forwardCurve(0));
         var steps        = block.GetStepsForFactor(path, _factorIndex);
         steps[0] = previousStep;
         for (var step = 1; step < block.NumberOfSteps; step++)
         {
             var W  = steps[step];
             var dt = new Vector <double>(_timesteps.TimeSteps[step]);
             var bm = (_drifts[step] - _vols[step] * _vols[step] / 2.0) * dt + (_vols[step] * _timesteps.TimeStepsSqrt[step] * W);
             previousStep *= bm.Exp();
             steps[step]   = previousStep;
         }
     }
 }
Ejemplo n.º 14
0
        public void Process(PathBlock block)
        {
            for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
            {
                //This should be set to the spot price here
                var previousStep = new Vector <double>(_spot);
                var steps        = block.GetStepsForFactor(path, _factorIndex);
                steps[0] = previousStep;
                for (var step = 1; step < block.NumberOfSteps; step++)
                {
                    var drift = _drift * _timesteps.TimeSteps[step] * previousStep;
                    var delta = _scaledVol * steps[step] * previousStep;

                    previousStep = (previousStep + drift + delta);
                    steps[step]  = previousStep;
                }
            }
        }
Ejemplo n.º 15
0
            public unsafe void Process(PathBlock block)
            {
                var currentIndex = 0 * block.NumberOfPaths * block.NumberOfSteps;

                for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
                {
                    //This should be set to the spot price here
                    var previousStep = Vector <double> .One;
                    for (var step = 0; step < block.NumberOfSteps; step++)
                    {
                        //ref Vector<double> currentValue = ref block.ReadVectorByRef(currentIndex);


                        //currentValue = Vector.Multiply(previousStep, currentValue);
                        //previousStep = currentValue;
                        //currentIndex += Vector<double>.Count;
                    }
                }
            }
Ejemplo n.º 16
0
        public static IPathBlock GetBlock(int nSteps)
        {
            var b = new PathBlock(_nPaths, 2, nSteps, 0);

            for (var i = 0; i < _nPaths; i += Vector <double> .Count)
            {
                var p = b.GetStepsForFactor(i, 0);
                for (var j = 0; j < nSteps; j++)
                {
                    p[j] = new Vector <double>(100.0);
                }
                var pfx = b.GetStepsForFactor(i, 1);
                for (var j = 0; j < nSteps; j++)
                {
                    pfx[j] = new Vector <double>(1.0);
                }
            }

            return(b);
        }
Ejemplo n.º 17
0
    private List <BlockController> FindPathThread(CellController start, CellController finish, bool checkObtacles = false)
    {
        var open   = new List <PathBlock>();
        var closed = new List <PathBlock>();

        var startBlock = new PathBlock(start.lastBlock)
        {
            h = GetDistance(start, finish)
        };

        var currentBlock = startBlock;

        open.Add(currentBlock);

        while (open.Count > 0)
        {
            closed.Add(currentBlock = open[0]);
            open.Remove(currentBlock);
            currentBlock.hs = GetDistance(currentBlock.block.cell, start.lastBlock.cell) / 10000F;

            if (currentBlock.block == finish.lastBlock)
            {
                return(GetPath(startBlock, currentBlock));
            }

            PutBlockIntoOpenList(open, closed, currentBlock, finish, -1, 0, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, 1, 0, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, 0, -1, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, 0, 1, checkObtacles);

            PutBlockIntoOpenList(open, closed, currentBlock, finish, -1, -1, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, 1, -1, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, -1, 1, checkObtacles);
            PutBlockIntoOpenList(open, closed, currentBlock, finish, 1, 1, checkObtacles);

            open.Sort(SortPathByF);
        }
        closed.Sort(SortPathByH);
        return(GetPath(startBlock, closed[0]));
    }
Ejemplo n.º 18
0
        public void Process(PathBlock block)
        {
            for (var path = 0; path < block.NumberOfPaths; path += Vector <double> .Count)
            {
                var steps         = block.GetStepsForFactor(path, _assetIndex);
                var previousIndex = new double[Vector <double> .Count];
                steps[0].CopyTo(previousIndex);
                steps[0] = new Vector <double>(0);
                for (var step = 1; step < block.NumberOfSteps; step++)
                {
                    var currentIndex = new double[Vector <double> .Count];
                    steps[step].CopyTo(currentIndex);

                    if (_logReturns)
                    {
                    }
                    else
                    {
                        steps[step] = new Vector <double>(currentIndex) / new Vector <double>(previousIndex) - new Vector <double>(1.0);
                    }
                    previousIndex = currentIndex;
                }
            }
        }
Ejemplo n.º 19
0
 public void Process(PathBlock block)
 {
     //NoOp
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates the next path block at the end of own corner.
 /// </summary>
 public void CreateNextPathBlock()
 {
     nextPB = LevelGenerator.Instance.CreatePathBlock (myCorner.position + myCorner.forward * 10f, myCorner.rotation);
     nextPB.previousPB = this;
 }
Ejemplo n.º 21
0
 public void Process(PathBlock block) => throw new NotImplementedException();
Ejemplo n.º 22
0
    private void PutBlockIntoOpenList(List <PathBlock> open, List <PathBlock> closed, PathBlock currentBlock, CellController finish,
                                      int offsetX, int offsetY, bool checkObtacles = false)
    {
        var nextCell = GetCell(currentBlock.block.cell.x + offsetX, currentBlock.block.cell.y + offsetY);

        if (nextCell == null || !IsCellAvailToMove(currentBlock.block.cell, nextCell, false, checkObtacles))
        {
            return;
        }

        var g = currentBlock.g + (currentBlock.block.cell.x != nextCell.x && currentBlock.block.cell.y != nextCell.y ? 141f : 100f);
        var h = GetDistance(nextCell, finish);

        var openBlock = open.Find(pathBlock => pathBlock.block.cell == nextCell);

        if (openBlock == null)
        {
            if (closed.Find(closedBlock => closedBlock.block.cell == nextCell) != null)
            {
                return;
            }
            open.Add(new PathBlock(nextCell.lastBlock)
            {
                g      = g,
                h      = h,
                parent = currentBlock
            });
        }
        else
        {
            if (!(openBlock.f > g + h))
            {
                return;
            }
            openBlock.g      = g;
            openBlock.h      = h;
            openBlock.parent = currentBlock;
        }
    }
Ejemplo n.º 23
0
 private static int SortPathByH(PathBlock cell1, PathBlock cell2)
 {
     return(cell1.fs > cell2.fs ? 1 : (cell1.fs < cell2.fs ? -1 : 0));
 }
Ejemplo n.º 24
0
 private static int SortPathByF(PathBlock cell1, PathBlock cell2)
 {
     return(cell1.f > cell2.f ? 1 : (cell1.f < cell2.f ? -1 : 0));
 }