/ParaBond/src/scaly/parabond/test/price/OnePortfolio00.scala
Scala | 96 lines | 48 code | 18 blank | 30 comment | 0 complexity | 1a8241c8f9041a27485936af26257b39 MD5 | raw file
- /*
- * Copyright (c) Scaly Contributors
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the Scaly Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- package scaly.parabond.test
- import org.scalatest.junit.JUnitSuite
- import org.junit.Assert._
- import org.junit.Test
- import org.apache.log4j.PropertyConfigurator
- import scaly.parabond.entry.SimpleBond
- import scaly.parabond.value.SimpleBondValuator
- import scaly.parabond.util.Helper
- import com.mongodb.casbah.MongoCursor
- import com.mongodb.casbah.MongoConnection
- import com.mongodb.casbah.commons.MongoDBObject
- import com.mongodb.BasicDBList
- import com.mongodb.BasicDBObject
- import scaly.parabond.util.MongoHelper
-
- class OnePortfolio00 {
- val fitter =
- List(
- 0.022250408186472507
- - 0.0034445001723609914,
- 0.0015772414196917963,
- -1.6876893139502916E-4,
- 7.1081143657141285E-6,
- -1.0265615090890005E-7)
-
- val mongo = MongoConnection("127.0.0.1")("parabond")
-
- @Test
- def test {
- val portfsCollecton = mongo("Portfolios")
-
- val portfsQuery = MongoDBObject("id" -> 1)
-
- val portfsCursor : MongoCursor = portfsCollecton.find(portfsQuery)
-
- val bondIds = MongoHelper.asList(portfsCursor,"instruments")
-
- val bondsCollection = mongo("Bonds")
-
- val t0 = System.nanoTime
-
- val value = bondIds.foldLeft(0.0) { (sum, id) =>
- val bondsQuery = MongoDBObject("id" -> id)
-
- val bondsCursor: MongoCursor = bondsCollection.find(bondsQuery)
-
- val bond = MongoHelper.asBond(bondsCursor)
-
- // print("bond(" + bond + ") = ")
- //
- val valuator = new SimpleBondValuator(bond, fitter)
-
- val price = valuator.price
-
- // println("%8.2f".format(price))
- //
- sum + price
- }
-
- val t1 = System.nanoTime
-
- val dt = (t1 - t0) / 1000000000.0
-
- println("value = %10.2f dt = %f".format(value,dt))
- }
-
- def process(bondIds : List[Int]) {
- bondIds.foreach(println)
- }
- }