Wednesday, March 16, 2011

Open source or free financial analysis programs/libraries

I'm looking for something containing similar functions to Matlab’s financial and financial derivatives toolbox but don’t have the cash to spend on matlab. I would appreciate any info on free or open source libraries or programs that will let me easily calculate interest rates, risk etc.

From stackoverflow
  • How about the Octave financial functions?

    http://www.gnu.org/software/octave/doc/interpreter/Financial-Functions.html#Financial-Functions

    I'm not familiar with the Matlab toolbox, so you'll have to judge for yourself.

    GNU Octave is a high-level language, primarily intended for numerical computations. It provides a convenient command line interface for solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly compatible with Matlab. It may also be used as a batch-oriented language.

  • How about JQuantLib or QuantLib?

    Jared : Octave doesn't do everything I want but quandlib should. I'm looking at using swig to allow me to call Quandlib functions from octave so I get the ability to deal with large datasets and run calculations with out needing to write a custom program to use Quantlib.
  • Exactly what functions do you need? How advanced? You have some financial functions in .Net

    Im sure it doesnt cover everything, but calulating interests and some other are no problem:

    http://msdn.microsoft.com/en-us/library/daksysx3(VS.80).aspx

    Calculate depreciation. DDB, SLN, SYD

    Calculate future value. FV

    Calculate interest rate. Rate

    Calculate internal rate of return. IRR, MIRR

    Calculate number of periods. NPer

    Calculate payments. IPmt, Pmt, PPmt

    Calculate present value. NPV, PV

When a Qt widget gets focus

I'm a new in Qt Designer 4.4.1 Open Source Edition. I used to program in Windows Borland C++ Builder and I've switched to Linux.

I do not know how to gain the control when a widget (a LineEdit in the specific case) gains the focus, no mater if by tab or by clicking or by any other medium. My Focus Policy to the widget is "strongFocus", so it is enabled to receive.

In Borland Builder, each object has a table with all possible events. For Edit field there is among the events one called "OnEnter" who signalizes the focus entering that object (similarly there is "OnExit")

Qt has something similar?
Can someone help me. I'll be gratefull. Luis

From stackoverflow
  • There is a "focusChanged" signal sent when the focus changes.
    It has two arguments, he widget losing focus and the one gaining focus.

  • I'd have to play with it, but just looking at the QT Documentation, there is a "focusInEvent". This is an event handler.

    Here's how you find information about.... Open up "QT Assistant". Go to the Index. Put in a "QLineEdit". There is a really useful link called "List of all members, including inherited members" on all the Widget pages. This list is great, because it even has the inherited stuff.

    I did a quick search for "Focus" and found all the stuff related to focus for this Widget.

  • Dear Bob

    Many thanks for your attention to my problem. Before putting the question I've done the reading yet, but I'tried to code, in the Form120's constructor like that:

    " connect(lineEdit12,SIGNAL(focusInEvent(lineEdit12)), this, SLOT(myroutine(void)));"

    g++ compiled well but during processing I received such messages:

    Object::connect: No such signal QLineEdit::focusInEvent(lineEdit12)

    Object::connect: (sender name: 'lineEdit12')

    Object::connect: (receiver name: 'Form120')

    please I ask your help. thanks Luis

    Max Howell : This isn't a forum, reply as a comment.
  • QWidget::setFocus() is slot, not signal. You can check if QLineEdit is in focus with focus property. QLineEdit emits signals when text is changed or edited, see documentation.

  • Qt Designer isn't designed for this level of WYSIWYG programming.

    Do it in C++:

    class LineEdit : public QLineEdit
    {
        virtual void focusInEvent( QFocusEvent* )
        {}
    };
    
  • You have hit on of the weird splits in QT, if you look at the documentation focusInEvent is not a slot it is a protected function, you can override it if you are implementing a subclass of your widget. If you you just want to catch the event coming into your widget you can use QObject::installEventFilter it let's you catch any kind of events.

    For some odd reason the developers of Trolltech decided to propagate UI events via two avenues, signals/slots and QEvent

    Max Howell : You can override a virtual base function. That is why events are virtual functions. Trolltech use signals instead when inheritance for that functionality is not likely to be useful.
  • The simplest way is to connect a slot to the QApplication::focusChanged signal.

  • You can add en event filter.
    This is an example of an application written with QtCreator. This form has a QComboBox named combobox.

    
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->comboBox->installEventFilter(this);
        .
        .
        .
    }
    
    bool MainWindow::eventFilter(QObject *object, QEvent *event)
    {
        if (event->type() == QEvent::FocusOut)
        {
            if (object == ui->comboBox)
            {
                qWarning(object->objectName().toLatin1().data());
            }
        }
        return false;
    }
    
    lostriebo : +1 Exactly what I was looking for, thank you!
  • Karl you are The Man!

Appropriate use of DL and DD?

I had some site templates designed for me recently. I got the final HTML code, which validates, but the structure of the document is laid out using DL-DD pairs:

<dl>
  <dd class="some-class">
    Some text.
  </dd>
</dl>

I'm not especially familiar with those tags as I've never used them much, but they don't seem intended for document structure. Am I right? Why would a designer do this?

From stackoverflow
  • From WC3: http://www.w3.org/TR/html401/struct/lists.html#h-10.3

    Definition lists vary only slightly from other types of lists in that list items consist of two parts: a term and a description. The term is given by the DT element and is restricted to inline content. The description is given with a DD element that contains block-level content.

    So given your example, these types of structures should be used for a specific type of content and not structuring of data that does not fit within this context.

    Ian : My main question is, is there any valid reason a designer would use these tags for document strucuture, or is this just WTF code?
    Gavin Miller : Ahh, I see; yes, this is a WTF piece of code.
  • You're right in that it shouldn't be used like that. The only reason I can think of for the designer using them is that the <dd> tag is indented in most browsers. If they're overriding the padding/margins on them, then your guess is as good as mine.

  • A DL tag is about the same as a UL tag, it starts an unordered list.

    The difference being that there basically is no bullet in a DL/DD couple.

    Most of the time, though, it's used for it's real use, that is, a Definition List, and is used with DT and DD, which are Definition Term and Definition Description which would look like :

    <DL>
      <DT>CSS</DT>
      <DD>Cascading Style Sheet</DD>
    </DL>
    

    which will, by default, indent the term a bit, and indent it's definition a bit more.

Is "Commit" necessary when updating Oracle from asp.net?

I have this code

    protected void btnUpdateAddress_Click(object sender, EventArgs e)
    {
        sdsAddressComparison.Update();
    }

that I'm using to update an oracle database. When I run the update sql code in SQL Navigator I have to type "Commit" or hit the commit button.

Do I have to code in a "Commit" somewhere in ASP.NET? and if so how and where do i do it?

From stackoverflow
  • Normally, No you do not need the commit.

    However you can write the code to use a transaction, and at the completion of the transaction you can call commit.

    E.G. (Regular):

    try {
            // Open connection
            dbConn.Open();
            //DB Update Code Here
        }
        catch (Exception ex) {
            throw;
        }
        finally {
            // Close database connection
            dbConn.Close();
        }
    

    E.G. (As Transaction):

    try {
            // Open connection & begin transaction
            dbConn.Open();
            dbTran = dbConn.BeginTransaction();
            
            //DB Update Code Here
            // Commit transaction
            dbTran.Commit();
        }
        catch (Exception ex) {
            // Rollback transaction
            dbTran.Rollback();
            throw;
        }
        finally {
            // Close database connection
            dbConn.Close();
        }
    
  • Just for clarification....I'm not talking about SQL Server transactions ....I'm talking about Oracle updates which usually require a commit command when I use either SQL navigator or SQL Plus

    The reason i'm posting this is because I can update this data in SQL Navigator but it doesn't update when I use ASP.NET.

    Brian Schmitt : Yep, you can do transactions in Oracle too.
    BQ : A transaction is a general concept, not a feature specific to SQL Server (or any other RDBMS). As is any DML (select/insert/update/delete) statement.
  • By default, your ASP.Net code, and most other client API's for databases (ODBC, OLE DB, JDBC, etc), run in auto-commit mode. That is, any time a statement is executed successfully, the result is committed. If you are running in that sort of a default mode, there is no need to explicitly commit your update.

    On the other hand, there is generally a great deal to be said for putting your updates in explicit transactions-- if you ever have to issue multiple updates in order to make one logical business change, the default auto-commit mode is a very poor one. The classic example here is that if you update account A to withdraw $50 and then update account B to deposit $50 and you end up having two different transactions because of auto-commit being enabled, it is possible that the first transaction would succeed while the other transaction fails and the system loses track of $50.

    So you generally want to write code similar to what Brian has demonstrated where you use transactions and issue the explicit commit. But by default, you don't have to and your updates will auto-commit.

    David Aldridge : +1: Yes, and I think that autocommit is a Very Bad Thing. If the associated problems are not already obvious, then let me add that it also harms performance on Oracle.
  • How do I check if autocommit is turned on?

    BQ : That depends on the application you're using to connect to the database. Look in SQL Navigator's options dialog.
  • The behavior you're seeing in SQL Navigator is probably determined by an options setting.

    I haven't used SQL Navigator, but I do use TOAD which is also by Quest Software. In the options dialog there, it's under View->Toad Options..., then the Oracle->Transactions node.

    There's the following relevant settings:

    • [ ] Commit after every statement (checkbox)

    • When closing connections: (radio selection)

      • ( ) Commit
      • ( ) Rollback
      • ( ) Prompt for commit/rollback when changes detected, or detection is not possible due to lack of privileges on dmbs_transaction.

    So you could change the setting so you don't need to hit the commit button (or type "commit"), but it's generally a bad practice since a commit is something that you should explicitly be doing (or explicitly rolling back).

  • Autocommit is also available in SQL*Plus.

    SET AUTOCOMMIT ON
    SET AUTOCOMMIT OFF
    

    or

    SET AUTOCOMMIT 100
    

    Use SHOW AUTOCOMMIT to see the current setting.

    But ... I hate this setting. You commit at the end of a meaningful unit of work, not part way through.

Accessing host machine IIS from a guest OS in VMWare

How can I access a site configured in IIS 7 on the host machine from a guest OS in VMWare (Fedora 10). I have configured the VM to use "NAT"

From stackoverflow
  • Depends on your network configuration of vmware product you are using (player, server, workstation). If it is set for a bridged mode, then you can do it as any other machine - by host machine's IP. If it is a "host only" or NAT mode - check what is the gateway IP for the guest (/sbin/route), and try using it:

    # /sbin/route
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    
    default         10.x.y.z        0.0.0.0         UG    0      0        0 eth0
    

    In this case, 10.x.y.z is the ip of the host machine.

    Nick : I am sorry, I am using NAT ..
    Nick : And i am using VMWare Workstation
    Sunny : So, there is a "private" network between the host and the guest. Make sure your IIS site binds to the "private" ip as well, not only to the "real" IP and localhost. Then, as I said, check in the guest what is the gateway IP, it is the same as the host "private" IP, so you can use it.
  • Pretty easy...

    Step 1 Configure IIS on the host OS to include a binding, if you would like to use a "url". for example mySite.com

    Step 2. In the Guest open up the hosts file c:\windows\system32\drivers\etc\hosts.

    Add the entry

    [hostip address] [host iis bining url]

    Example

    192.168.0.1 mySite.com

    restart your browser in the guest, and you should be good to go.

    Jan Aagaard : Why not simply type the IP number of the host in the address bar in the browser on the guest?

Measuring trust for users of a service.

Lets say you have a program that allows access to some sort of media. This media can be damaged. It is only possible for the users to know if the media is damaged after they use the service and receive the media. So to make your users happy, you want your program to give the users the ability to turn the media back in for a refund. However malicious users will obviously try to game this system by asking for refund on perfectly good media.

The question is what would be a good algorithm to decide whether or not to trust a given user. How should users build trust? How should trust be spent?

I imagine there must be some academic research on how to construct 'trust' values for known users and so on. Anyone have links to papers or some sort of research? I would even be happy to read random thoughts on the problem but I am more interested in actual papers.

From stackoverflow
  • If you are referring to physical media, the first analogy is buying a CD, DVD or video game from a store. If you return it, they won't give you a refund, but they will give you a non-defective copy if that was your problem.

    There's no reason for a user to suddenly decide not to have the media if the first copy was bad if they can easily get a second, non-defective copy for free.

  • To clarify....

    There are no humans involved in this process. Users approach the service, use it, attempt to consume the media then a chance of a problem. If there is a problem then the users want to get a refund. The question is how to build data over time as to the trustworthiness of a given user.

    The bad user scenario would go something like: User consumes media successfully, lies to the service, asks for refund.

    Marcin : If no humans are involved, what are the users?
    Tim : you need to provide more information - there may be limiting aspects to this. The user may need to provide more information for a refund so you can track abuse. Alternatively/also you can issue a credit rather than a refund.
  • This is very programming related, it would be describing an algorithm.

    Although I've never seen a paper on the scenario you are discussing, it seems like it should be pretty straight-forward. I think I would track two axis--By media and by user in a pretty simple, liner fashion.

    First of all, at some point the sales/returns ratio should be able to indicate that you need to pull the item, that'd be my first line of defense!

    If a user asks for a refund, I'd check the sales/returns ratio, if it's not Very Low, there is a good chance the media is bad. In this case I'd allow the refund (and increment the user's trust)

    If the ratio is very low AND the total number of sales is low, I'd check the trust stat and if it's high, allow the return and adjust stats (but I wouldn't increment the trust stat except in the above case--because in that case it correlates with other users)

    If the number of sales is high and the number of returns is low AND the user has a low "trust" stat, Then I'd deny it.

    edit:

    Also, I'd track all refunds separately, exactly who returned what and not just a simple counter as my post implies. In that way, if your algorithm is insufficient, you could implement a new algorithm that could recalculate your existing data on the fly.

    It could also be used to evaluate patterns of abuse--in other words, if you do identify a pattern someone has been using to scam the system, you could create a new pattern detector and execute it to find other accounts that have been using the same pattern, then show them goatse or something next time they make a request.

Detecting Vista IE7 Protected Mode with Javascript

I'd like to be able to detect Vista IE7 Protected Mode within a page using javascript, preferably. My thinking is to perform an action that would violate protected mode, thus exposing it. The goal is to give appropriate site help messaging to IE7 Vista users.

From stackoverflow
  • What are you trying to accomplish that is substantially different for protected users? I've seen some window popup issues, but otherwise, clean JavaScript tends to be less affected. If you're finding that a block of code won't execute, why not do a check after attempted execution to see if the document is the state you expect, and alert if not.

    If it's it using ActiveX, MS has a Protected Mode API: http://msdn.microsoft.com/en-us/library/ms537316(VS.85).aspx

    Protected mode is customizable, so you don't really have a reliable way of detecting it based on action violation. And many users disable UAC, so detecting via version won't work either (not to mention you may have the same headache with IE 8. Always best to test if something worked instead of assume by version.)

  • Adobe Flash may behave differently (or not as expected) in Vista IE7 Protected Mode. The intention is to provide this feedback to the user.

    Mr. Shiny and New : If I had Flash which wasn't working in protected mode, I'd try to fix my use of Flash to work around that. Many users won't understand the problem if you explain it, and those that do may be unwilling to turn off protected mode. (unless, of course, you have a safe workaround...)
  • I reviewed the MSDN documentation of the Protected Mode API from 6t7m4, and if I could call the ieframe.dll from javascript, such as:

    var axo = new ActiveXObject("ieframe.dll");
    

    I would be able to access the IEIsProtectedModeProcess() function, but I believe it's inaccesible due to security reasons.

    recursive : You should include these updates as edits to your original question.